﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Specialized;
using System.Data.SqlClient;



public partial class pages_PersonnelOffice_WorkingReport_Default : System.Web.UI.Page
{

  string ConnectionString = ConfigurationManager.ConnectionStrings["dataBaseConnection"].ConnectionString;
  SqlConnection sqlcon;
  protected void Page_Load(object sender, EventArgs e)
  {
      DropDownList ddl;
      //  dt.ToString("HH时mm分ss秒");
      DateTime date=System.DateTime.Now;
      string datetemp=date.ToString("HH:mm");
      if (!IsPostBack)
      {
          string sqlstr = "select top 5 * from system_employee";
          sqlcon = new SqlConnection(ConnectionString);
          SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);
          DataSet myds = new DataSet();
          sqlcon.Open();
          myda.Fill(myds, "system_employee");
          GridView1.DataSource = myds;
          GridView1.DataBind();
          for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
          {
              DataRowView mydrv = myds.Tables["system_employee"].DefaultView[i];
              if (Convert.ToString(mydrv["emp_code"]).Trim() == "True")
              {
                  ddl = (DropDownList)GridView1.Rows[i].FindControl("DropDownList1");
                  ddl.SelectedIndex = 0;
              }
              if (Convert.ToString(mydrv["emp_code"]).Trim() == "False")
              {
                  ddl = (DropDownList)GridView1.Rows[i].FindControl("DropDownList1");
                  ddl.SelectedIndex = 1;
              }
          }
          sqlcon.Close();
      }
  }
  public SqlDataReader ddlbind()
  {
      string sqlstr = "select distinct emp_code,emp_name from system_employee";
      sqlcon = new SqlConnection(ConnectionString);
      SqlCommand sqlcom = new SqlCommand(sqlstr, sqlcon);
      sqlcon.Open();
      return sqlcom.ExecuteReader();
  }


    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        bind();
    }

    //取消
    protected void GridView1_RowCancelingEdit1(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        bind();

    }



    //绑定
    public void bind()
    {
        string sqlstr = "select * from system_employee";
        sqlcon = new SqlConnection(ConnectionString);
        SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);
        DataSet myds = new DataSet();
        sqlcon.Open();
        myda.Fill(myds, "system_employee");
        GridView1.DataSource = myds;
        GridView1.DataKeyNames = new string[] { "emp_code" };//主键
        GridView1.DataBind();
        sqlcon.Close();
    }


}
